<template>
  <div>
    <a-card :bordered="false" >
      <div>   
        <div :class="advanced ? 'search' : null">
          <a-form layout="horizontal">
            <div :class="advanced ? null: 'fold'">
              <a-row>
                <a-col :md="8" :sm="24" >
                  <a-form-item
                    label="网址"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                  >
                    <a-input placeholder="请输入网址" v-model="url" />
                  </a-form-item>
                </a-col>
              </a-row>
            </div>
            <span style="float: right; margin-top: 3px;">
              <a-button type="primary" @click="search">查询</a-button>
              <a @click="toggleAdvanced" style="margin-left: 8px">
                {{advanced ? '收起' : '展开'}}
                <a-icon :type="advanced ? 'up' : 'down'" />
              </a>
            </span>
          </a-form>
        </div>
        <standard-table
          bordered 
          rowKey="id"
          :loading='loading'
          :columns="columns"
          :dataSource="dataSource"
          :pagination="{total:dataSource.length,pageSize:10,current:page,showTotal:total => `共 ${total} 件`}"
          @clear="onClear"
          @change="onChange"
        >
          <div slot="yemian" slot-scope="{record}">
            <a :href="record.yemian">{{record.yemian}}</a>
          </div>
        </standard-table>
      </div>
    </a-card>
  </div>
</template>

<script>
import axios from 'axios'
import StandardTable from '@/components/table/StandardTable'

export default {
  components:{StandardTable},
  data() {
    return {
      labelCol: {span: 5},
      wrapperCol: {span: 18, offset: 1},
      advanced: false,
      columns:[
        {
          title: '页面',
          dataIndex: 'yemian',
          scopedSlots: { customRender: 'yemian' }
        },
        {
          title: '外链',
          dataIndex: 'lianjie',
        },
      ],

      url:'',
      page:1,
      dataSource:[],
      loading:false
    }
  },
  methods: {
    search(){
      let params = {
        url:this.url
      }
      this.loading = true
      axios.post('/pa/search',params).then((res)=>{
        this.loading = false
        this.dataSource = res.data.data
      }).catch((err)=>{
        console.log(err)
        this.loading = false
      })
    },
    onClear() {
      this.$message.info('您清空了勾选的所有行')
    },
    onChange(e) {
      this.page = e.current
    },

    toggleAdvanced () {
      this.advanced = !this.advanced
    },
  },
}
</script>

<style scoped>
  .search{
    margin-bottom: 40px;
  }
  .fold{
    width: calc(100% - 216px);
    display: inline-block
  }
</style>